package de.baumann.browser.activitys

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.text.Editable
import android.text.TextWatcher
import de.baumann.browser.R
import de.baumann.browser.base.BaseOdinActivity
import de.baumann.browser.iview.IFeedbackView
import de.baumann.browser.present.FeedbackPresenter
import de.baumann.browser.utils.ViewUtil
import kotlinx.android.synthetic.main.activity_feed_back.*
import kotlinx.android.synthetic.main.include_tool_bar.*

/**
 * @author：
 * @date：2018/10/19
 * @discription: 意见反馈
 */
class FeedBackActivity : BaseOdinActivity<IFeedbackView, FeedbackPresenter>(), IFeedbackView {

    private val maxNum = 240

    private val mTextWatcher = object : TextWatcher {
        @SuppressLint("SetTextI18n")
        override fun afterTextChanged(s: Editable) {
            var num = s.length
            num = maxNum - num
            tvInputNUm!!.text = "$num/$maxNum"
        }

        override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}

        override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {}
    }

    override fun getTitleText(): String {
        return getString(R.string.feedback)
    }

    override fun getLayout(): Int {
        return R.layout.activity_feed_back
    }

    override fun initView() {
        initToolbar(commToolBar, commTitle)
        feedRoot.setPadding(0, ViewUtil.getStatusBarHeight(mContext), 0, 0)
        edFeedbackContent.addTextChangedListener(mTextWatcher)
        btnFeedback.setOnClickListener { presenter.feedback() }
    }

    override fun initData() {
    }

    override fun createPresenter(): FeedbackPresenter? {
        return FeedbackPresenter()
    }

    override fun createView(): IFeedbackView? {
        return this
    }

    override fun getContent(): String {
        return edFeedbackContent.text.trim().toString()
    }

    override fun feedbackSuccess() {
        showShortToast(getString(R.string.feedback_success))
        finish()
    }

    companion object {

        fun startFeedBackActivity(context: Context) {
            context.startActivity(Intent(context, FeedBackActivity::class.java))
        }
    }
    override fun showBindEth(): Boolean {
        return false
    }

}
